<template>
  <div class="input-container">
    <input
      v-model="newTodo"
      @keyup.enter="addTodo"
      placeholder="添加新任务..."
      class="todo-input"
    />
    <button @click="addTodo" class="add-btn">添加</button>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const emit = defineEmits(['add-todo']);

const newTodo = ref('');

const addTodo = () => {
  if (newTodo.value.trim() === '') return;
  
  emit('add-todo', newTodo.value.trim());
  newTodo.value = '';
};
</script>

<style scoped>
.input-container {
  display: flex;
  margin-bottom: 20px;
}

.todo-input {
  flex: 1;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
  font-size: 16px;
}

.add-btn {
  padding: 10px 15px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  font-size: 16px;
}

.add-btn:hover {
  background-color: #369f6b;
}
</style>